package org.test;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class DispServlet extends HttpServlet {
  //Process the HTTP Get request
	public void doGet(HttpServletRequest request,HttpServletResponse response)throws
	ServletException,IOException{
		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out=response.getWriter();
	    ServletContext context=getServletContext();
	    out.println("<html>");
	    out.println("<head>");
	    out.println("<meta http-equiv='refresh' content='3'/>");
	    out.println("<title>MessageServlet</title></head>");
	    out.println("<body bgcolor=\"#ffffff\">");
	    request.setCharacterEncoding("UTF-8");
	    out.println("内容");
	    //显示聊天信息
	    Vector hab=(Vector)context.getAttribute("messagelist");
	    out.println("<textarea name='info' rows='16' cols='50'>");
	    for(int i=0;i<hab.size();i++){
	    	out.println(hab.get(i));
	    }
	    out.println("</textarea>");
	    out.println("用户列表");
	    out.println("<textarea name='user' rows='16' cols='25'>");
	    //显示用户列表
	    Vector vc=(Vector)context.getAttribute("userlist");
	    for(int i=0;i<vc.size();i++){
	    	if(vc.get(i)!=null)
	    		out.println(vc.get(i));
	    }
	    out.println("</textarea>");
	    out.println("</body>");
	    out.println("</html>");
	    out.close();
	}
	public void doPost(HttpServletRequest request,HttpServletResponse response)throws
	   IOException,ServletException{
		  doGet(request,response);
	  }
}